from sqlalchemy import Column, Integer, String, Numeric, DateTime, ForeignKey
from sqlalchemy.sql import func
from ..core.database import Base

class GroupBuyOrder(Base):
    __tablename__ = "group_buy_orders"
    
    id = Column(Integer, primary_key=True, index=True)
    product_id = Column(Integer, ForeignKey("products.id"), nullable=False)
    total_shares = Column(Integer, nullable=False)
    sold_shares = Column(Integer, default=0)
    status = Column(Integer, default=1)  # 1:拼购中 2:拼购成功 3:拼购失败
    start_time = Column(DateTime(timezone=True), server_default=func.now())
    end_time = Column(DateTime(timezone=True))
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now()) 